package service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

import dao.CategoryDAO;
import dao.QueryDAO;
import dao.RecordDAO;
import entity.Category;
import entity.Query;
import entity.Record;
import gui.panel.QueryPanel;

public class QueryService {
	QueryDAO queryDao = new QueryDAO();
    RecordDAO recordDao = new RecordDAO();

	QueryPanel queryPanel = QueryPanel.instance;
 
    public List<Query> list() {
        List<Query> qs= queryDao.list();
//        for (Query q : qs) {
//            List<Record> rs =recordDao.list();
//            q.id=rs.size();
//        }
//        Collections.sort(qs,(q1,q2)->q2.id-q1.id);
        return qs;
    }
    
    public List<Query> listReQueries(String tfSpendl,String tfSpendr,Date datepickerl,Date datepickerr,String tfComment) {
        List<Query> qs= queryDao.listReQueries(tfSpendl,tfSpendr,datepickerl,datepickerr,tfComment);
        return qs;
    }
    
    public void update(int spend, Category c, String comment,java.sql.Date date,int id) {
        Query q = new Query();
        q.spend = spend;
        q.cid = c.id;
        q.comment = comment;
        q.date = date;
        q.id = id;
        queryDao.update(q);
    }
    
 
    public void delete(int id) {
    	queryDao.delete(id);
    }
}
